//
//  HWVoiceRoomGiftSendView.swift
//  PlayWithProject
//
//  Created by 王昌健 on 2021/8/30.
//

import UIKit

class HWVoiceRoomGiftSendView: UIView {
    var bgView:UIView!
    var sendButton:UIButton!
    var leftView:UIView!
    var numBgView:UIView!
    var numLabel:UILabel!
    var arrowImage:UIImageView!
    var numButton:UIButton!
    
    var sendButtonClick:((_:String)->())?
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        initUI()
        
        initFrame()
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
extension HWVoiceRoomGiftSendView {
    private func initUI() -> Void {
        bgView = UIView()
        bgView.backgroundColor = .clear
        bgView.layer.cornerRadius = 14
        bgView.layer.borderWidth = 1
        bgView.layer.borderColor = UIColor.colorWithHexString(hexString: "#FDDD00").cgColor
        bgView.layer.masksToBounds = true
        addSubview(bgView)
        
        sendButton = UIButton(type: .custom)
        sendButton.setTitle("赠送", for: UIControl.State.normal)
        sendButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 14)
        sendButton.setTitleColor(.colorWithHexString(hexString: "#333333"), for: UIControl.State.normal)
        sendButton.backgroundColor = .colorWithHexString(hexString: "FDDD00")
        sendButton.addTarget(self, action: #selector(sendButtonClick(_:)), for: UIControl.Event.touchUpInside)
        bgView.addSubview(sendButton)
        
        leftView = UIView()
        bgView.addSubview(leftView)
        
        numBgView = UIView()
        leftView.addSubview(numBgView)
        
        numLabel = HWLabel.createBoldLabel(title: "1", color: "#FFFFFF", font: 14)
        numBgView.addSubview(numLabel)
        
        arrowImage = UIImageView()
        arrowImage.image = UIImage(named: "giftArrow")
        numBgView.addSubview(arrowImage)
        
        numButton = UIButton(type: .custom)
        numButton.addTarget(self, action: #selector(numButtonClick(_:)), for: UIControl.Event.touchUpInside)
        leftView.addSubview(numButton)
    }
    
    private func initFrame() -> Void {
        bgView.snp.makeConstraints { make in
            make.left.right.top.bottom.equalTo(0)
            make.height.equalTo(28)
            make.width.equalTo(126)
        }
        sendButton.snp.makeConstraints { make in
            make.right.top.bottom.equalTo(0)
            make.left.equalTo(bgView.snp.centerX)
        }
        
        leftView.snp.makeConstraints { make in
            make.left.top.bottom.equalTo(0)
            make.right.equalTo(bgView.snp.centerX)
        }
        
        numBgView.snp.makeConstraints { make in
            make.center.equalTo(leftView)
        }
        
        numLabel.snp.makeConstraints { make in
            make.left.top.bottom.equalTo(0)
        }
        
        arrowImage.snp.makeConstraints { make in
            make.left.equalTo(numLabel.snp.right).offset(5)
            make.right.equalTo(0)
            make.centerY.equalTo(numLabel)
        }
        
        numButton.snp.makeConstraints { make in
            make.left.right.top.bottom.equalTo(0)
        }
        
    }
}

extension HWVoiceRoomGiftSendView {
    @objc func numButtonClick(_ button:UIButton) -> Void {
//        var image = UIImage(named: "giftArrow")
//        image = UIImage.init(cgImage: (image?.cgImage)!, scale: image!.scale, orientation: UIImage.Orientation.down)
//        arrowImage.image = image
    }
    
    @objc func sendButtonClick(_ button:UIButton) -> Void {
        sendButtonClick?(numLabel.text ?? "1")
        
    }
}
